package com.leetcode.algorithm.y22.m06;

/**
 * 1309. 解码字母到整数映射
 * 
 * https://leetcode.cn/problems/decrypt-string-from-alphabet-to-integer-mapping/
 * 
 * @author jie.deng
 *
 */
class Question1309Solution01 {
	
	public String freqAlphabets(String s) {
		int len = s.length();
		StringBuilder builder = new StringBuilder(len);
		int idx = len - 1;
		while (idx >= 0) {
			char ch = s.charAt(idx);
			if (ch == '#') {
				builder.insert(0, (char) ((s.charAt(idx - 2) - '0') * 10 + (s.charAt(idx - 1) - '0') - 1 + 'a'));
				idx -= 3;
			} else {
				builder.insert(0, (char) (ch - '0' - 1 + 'a'));
				idx -= 1;
			}
		}
		return builder.toString();
	}
    
}